#include <iostream>
#include <fstream>

using namespace std;

int main() {
    const char* name = "./test.txt";
    ifstream ifs(name, ios::binary); // 以二进制模式打开文件

    // 判断文件是否打开成功
    if (!ifs.is_open()) {
        cout << "open error" << endl;
        exit(-1);
    }

#if 0
    // 读取指定数量的字节
    const int BUFFER_SIZE = 20;
    char buf[BUFFER_SIZE];
    ifs.read(buf, BUFFER_SIZE - 1); // 读取 BUFFER_SIZE - 1 个字节
    buf[ifs.gcount()] = '\0'; // 添加字符串结束符
    cout << "Read " << ifs.gcount() << " bytes: " << buf << endl;
#endif
    char buf[13] = {0};
    do
    {
        ifs.read(buf, 12);
        if(ifs.gcount() != 0)
        {
            cout << buf;
        }
    } while (ifs.gcount() == 12);
    
    
    // 关闭文件
    ifs.close();

    return 0;
}
